package cn.com.elite;

import java.util.List;

import javax.sql.DataSource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;

public class EliteBean {
	private static final Log log=LogFactory.getLog(EliteBean.class);
	private DataSource dataSource;
    private DataSourceTransactionManager tran;
	public DataSource getDataSource() {
		return dataSource;
	}
	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	}
	
	public List QueryPersonUseExecute(String sql,int[] types,Object[] params)throws Exception{
		JdbcTemplate jdbcTemplate=new JdbcTemplate(dataSource);
		List result=null;
		log.debug("sql:"+sql);
		try{
			result=jdbcTemplate.queryForList(sql,params,types);
		}catch(Exception e){
			 log.error("出错types："+getcontent1(types));
			 log.error("出错params："+getcontent(params));
			 log.error("出错SQL："+sql);
			 throw e;  
		}
		return result;
	}
	public static String getcontent(Object[] a){
    	String b="";
    	if(a!=null&&a.length>0){
    		for(int i=0;i<a.length;i++){
    			if(a[i]!=null){
    				b=b+"a["+i+"]："+a[i].toString()+"-";	
    			}else{
    				b=b+"a["+i+"]：null-";	
    			}
    		}
    	}
    	return b;
    }
	public static String getcontent1(int[] a){
    	String b="";
    	if(a!=null&&a.length>0){
    		for(int i=0;i<a.length;i++){
    			b=b+"a["+i+"]："+a[i]+"-";
    		}
    	}
    	return b;
    }

}
